package com.suxin.classloader;

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.jar.Manifest;

/**
 * @author Tang
 * @classname Archive
 * @description [ 统一资源访问层 ]
 * @date 2023/1/5 22:39
 */
public interface Archive extends Iterable<Archive.Entry>,AutoCloseable {

    /**
     * getUrl
     * @return
     * @throws Exception
     */
    URL getUrl() throws Exception;

    /**
     * getManifest
     * @return
     * @throws IOException
     */
    Manifest getManifest() throws IOException;

    /**
     * getNestedArchive
     * @param filter
     * @return
     */
    List<Archive> getNestedArchive(EntryFilter filter);

    @Override
    default void close() throws Exception{

    }

    interface Entry {

        /**
         * isDirectory
         * @return
         */
        boolean isDirectory();

        /**
         * getName
         * @return
         */
        String getName();
    }


    interface EntryFilter {

        boolean matches(Entry entry);
    }

}
